import React from 'react';
import { View, Button, StyleSheet } from 'react-native';
import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';

export default function SimpleShare() {
  const handleShare = async () => {
    try {
      const message = "Hello from Expo App!";
      const fileUri = FileSystem.documentDirectory + 'message.txt';
      await FileSystem.writeAsStringAsync(fileUri, message);
      
      if (await Sharing.isAvailableAsync()) {
        await Sharing.shareAsync(fileUri);
      } else {
        alert('分享功能在此设备上不可用');
      }
    } catch (error) {
      alert('分享失败');
    }
  };

  return (
    <View style={styles.container}>
      <Button title="分享文本" onPress={handleShare} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});